// miniprogram/pages/bmrs/bmrs.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:66
  },
  //点击选择-省份地市
  choisezhuguanbumen() {
    var that = this;
    that.setData({
      bindpro: 1,
    })
  },
  //一级联动-省份
  zhuguanbumen() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=42892&callback=?', //接收url
      data: {
        level: '1',
        zhuguanbumen: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
          console.log(theJson)
        }
        //console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhuguanbumen)
        }
        // console.log(list)
        that.setData({
          zhuguanbumenList: list
        });
      }
    })
  },
  //点击选择-省份
  setzhuguanbumen(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zhuguanbumen)
    that.setData({
      zhuguanbumen: e.currentTarget.dataset.zhuguanbumen
    })
    that.danwei()
  },
  //点击重新选择-省份
  rechoisezhuguanbumen() {
    var that = this;
    that.setData({
      danweiList: !1,
      danwei: !1
    })
  },
  //二级联动-地市
  danwei() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=42892&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'zhuguanbumen',
        grtext: that.data.zhuguanbumen
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        // console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].danwei)
        }
        console.log(list)
        that.setData({
          danweiList: list
        });
      }
    })
  },
  //点击选择-地市
  setdanwei(e) {
    var that = this;
    console.log(e.currentTarget.dataset.danwei)
    that.setData({
      danwei: e.currentTarget.dataset.danwei,
      danweiList: !1,
      bindpro: !1
    })
  },

  //点击选择-政治面貌gangweimingcheng
  choisegangweimingcheng() {
    var that = this;
    if (that.data.danwei) {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=42892&callback=?', //接收url
        data: {
          level: '3',
          grfiled: 'danwei',
          grtext: that.data.danwei,
          onefiled: 'zhuguanbumen',
          onetext: that.data.zhuguanbumen
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          var list = [];
          for (var i in theJson.lists) { //循环写入下来框
            list.push(theJson.lists[i].gangweimingcheng)
          }
          console.log(list)
          that.setData({
            gangweimingchengList: list,
            bindgangweimingcheng: 1
          });
        }
      })
    } else {
      wx.showToast({
        title: '请先选择地市',
        icon: 'none'
      })
    }

  },
  //点击选择-政治面貌gangweimingcheng
  setgangweimingcheng(e) {
    var that = this;
    console.log(e.currentTarget.dataset.gangweimingcheng)
    that.setData({
      gangweimingcheng: e.currentTarget.dataset.gangweimingcheng,
      bindgangweimingcheng: !1
    })
  },
  closeselect() {
    var that = this;
    that.setData({
      bindpro: !1,
      bindgangweimingcheng: !1,
    })
  },
    //关闭透明层
    hideRule: function () {
      this.setData({
        isRuleTrue: false
      })
    },
    lingqu(){
      wx.navigateTo({
        url: '../../web1/web1' ,
      })
    },
  //个人信息查询提交
  submit() {
    var that = this;
    var phone = wx.getStorageSync('bmrsphone')
    if (phone) {
      if (that.data.danwei) {
        that.setData({
          isRuleTrue: true
        })
      } else {
        wx.showToast({
          title: '请选择工作地点',
          duration: 2000,
          icon: 'none'
        })
      }

    } else {
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      })
      that.setData({
        fixed: 1
      })
    }
  },
  getPhoneNumber(e) {
    var that = this;
    var fenxiao = that.data.area;
    var geneal = that.data.geneal;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('bmrsphone', res.result)
      console.log(res.result)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=42892&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: fenxiao,
          geneal: geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          that.setData({
            fixed: !1
          })
        }
      })

      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 37,
          mobile: res.result,
          areaCode: that.data.area,
          agent: that.data.geneal,
          pageId: that.data.page
        },
        success: res => {
          console.log(res);
        }
      })
    }).catch(err => {
      console.error(err);
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
  },
    // 键盘抬起事件
    inputTyping: function (e) {
      var value = e.detail.value
      var that = this;
      if (value == '') {
        that.setData({
          viewShowed: false,
        });
      } else {
        //“这里需要特别注意，不然在选中下拉框值的时候，下拉框又出现”
        if (e.detail.cursor) { //e.detail.cursor表示input值当前焦点所在的位置

        }
      }
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})